import {Component, Input, OnInit} from '@angular/core';

@Component({
    selector: 'app-doc-mock-review',
    templateUrl: './doc-mock-review.component.html',
    styleUrls: ['./doc-mock-review.component.css']
})
export class DocMockReviewComponent {
    private _response: string;

    responseJson: any;

    responseJsonMd: string;

    reviewTabStatus = 'json';

    constructor() {
    }

    setReviewTabStatus(tabName: string) {
        this.reviewTabStatus = tabName;
    }

    get response(): string {
        return this._response;
    }

    @Input()
    set response(value: string) {
        this._response = value;
        if (!value) {
            this.responseJson = null;
            this.responseJsonMd = null;
        } else {
            this.responseJson = JSON.parse(value);
            this.responseJsonMd = '```json \n' + JSON.stringify(this.responseJson, null, '  ') + '\n```';
        }
    }

}
